package genericclass;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-06-01
 * Time: 9:15
 */

/**
 * 泛型
 * @param <T>
 */
class MyArray<T extends Object> {
    public Object[] array = new Object[10];
    public T getValue(int pos) {
        return (T)array[pos];
    }
    public void setValue(int pos,T value) {
        array[pos] = value;
    }

}
public class Test {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<>();
        myArray.setValue(0,0);
        myArray.setValue(1,1);
        myArray.setValue(2,2);
        for (int i = 0; i < 3; i++) {
            Integer integer = myArray.getValue(i);
            System.out.println(integer);
        }
        System.out.println("===========");
        MyArray<String> myArray1 = new MyArray<>();
        myArray1.setValue(0,"dings");
        myArray1.setValue(1,"zhen");
        myArray1.setValue(2,"ben");
        for (int i = 0; i < 3; i++) {
            String x = myArray1.getValue(i);
            System.out.println(x);
        }

    }
}
